package com.ppt.javappt.util;

import com.ppt.javappt.entity.SlideFile;
import com.ppt.javappt.entity.SlideStackPane;
import com.ppt.javappt.entity.ThumbnailPane;
import javafx.scene.Node;
import javafx.scene.Parent;
import lombok.Getter;

/**
 * @author cys
 */
public class SystemUtil {
    @Getter
    private SlideFile curSlideFile;

    @Getter
    private static SystemUtil instance = new SystemUtil();

    public SlideStackPane getSlideStackPane(){
        return curSlideFile.getSlideStackPane();
    }

    public ThumbnailPane getThumbnailPane(){
        return curSlideFile.getThumbnailPane();
    }


    private SystemUtil(){
        curSlideFile = new SlideFile();
    }

    public void setCurSlideFile(SlideFile curSlideFile) {
        this.curSlideFile = curSlideFile;
    }

    // 判断child是否是Parent的子节点
    public static boolean isDescendant(Node parent, Node child){
        if (child == null) {
            return false;
        }
        Parent curParent = child.getParent();
        while (curParent != null) {
            if (curParent == parent) {
                return true;
            }
            curParent = curParent.getParent();
        }
        return false;
    }
}
